
/**
 * 参考：https://github.com/Tencent/vConsole/blob/dev/README_CN.md
 * */
import { Storage } from '../storage/storage.js';
import { Platform } from '../platform/platform.js';
//#ifdef H5
import './vconsole.min.js';
//#endif

let vconsole = null;

/**
 * @description 开启 VConsole
 * @param {Boolean} force 生产环境是否强制开启
 * @return {Boolean} 是否开启成功
 * */
export const openVConsole = (force=false) => {
	if(Platform.isProdEnv && force === false){
		closeVConsole();
		return false;
	}
	if (vconsole !== null) {
		return false;
	}
	if ((Platform.isH5) && window['VConsole']) {
		vconsole = new window['VConsole']();
		Storage.set('vconsole', true);
		return true;
	} else {
		return false;
	}
}

/**
 * @description 关闭 VConsole
 * @return {Boolean} 是否关闭成功
 * */
export const closeVConsole = () => {
	if (vconsole !== null) {
		vconsole.destroy();
		vconsole = null;
		Storage.set('vconsole', false);
		return true;
	} else {
		return false;
	}
}


export class VConsole {
	static open = openVConsole;
	static close = closeVConsole;
}

